import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    state.routes = [...constantRoutes, ...data]// 拼接动态和静态页面路由
  }
}
const actions = {
  filterRoutes(store, data) {
    // console.log('用户的权限', data)
    // console.log('动态路由', asyncRoutes)
    const routes = asyncRoutes.filter(item => data.indexOf(item.name) !== -1)
    // console.log('能访问页面的权限', routes)
    store.commit('setRoutes', routes)// 将过滤后的页面传给vuex  routes
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
